import request from "@/utils/request";

export class CURDApiBase {
  constructor(public baseUrl: string) {}

  // 详情
  detail(id: string) {
    return request({
      url: `${this.baseUrl}/${id}`,
      method: "get",
    });
  }

  // 获取列表
  list(data?): Promise<any> {
    return request({
      url: `${this.baseUrl}/list`,
      method: "post",
      data,
    });
  }

  // 新增/修改
  save(data: any): any {
    return request({
      url: `${this.baseUrl}/`,
      method: "post",
      data,
    });
  }

  // 删除
  del(id: string): any {
    return request({
      url: `${this.baseUrl}/${id}`,
      method: "delete",
    });
  }

  // 批量删除
  batchDel(data: any): any {
    return request({
      url: `${this.baseUrl}/batch-del`,
      method: "post",
      data,
    });
  }

  // 导出
  export(data?: any): any {
    return request({
      url: `${this.baseUrl}/export`,
      method: "post",
      data,
    });
  }

  // 导入
  import(save: Boolean, data?: any): any {
    return request({
      headers: {
        "content-Type": "multipart/form-data",
      },
      url: `${this.baseUrl}/import/${save}`,
      method: "post",
      data,
    });
  }
}
